home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14259 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: bmtlh10.bnr.ca!news
  2. From: John Hickin <hickin@bnr.ca>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: MFC ASSERT_VALID
  5. Date: 29 Mar 1996 17:51:35 GMT
  6. Organization: Bell Northern Research
  7. Message-ID: <4jh7v7$6k@bmtlh10.bnr.ca>
  8. References: <315C185D.6B46@garlic.com>
  9. NNTP-Posting-Host: bmtlh520.bnr.ca
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1 (X11; I; HP-UX A.09.05 9000/715)
  14. X-URL: news:315C185D.6B46@garlic.com
  15.  
  16. {   // This doesn't...
  17.         CAge* pCAge = (CAge*) new char[1 * sizeof(CAge)];  //1
  18.         pCAge[0] = CAge(21);                   //2
  19.         ASSERT(pCAge[0] == CAge(21)); // OK
  20.         ASSERT_VALID(&pCAge[0]); // AfxIsValidAddress fails:
  21.                                  // "illegal vtable pointer"
  22.         delete[] (char*)pCAge;
  23.     }
  24.  
  25. This can't work because the statement //1 does not initialize the memory
  26. returned by new   The CAge constructor is never called.  So you think
  27. you have a valid initialized CAge instance when you don't.
  28.  
  29. Now the statement //2 is set up to fail because operator= assumes that
  30. the LHS is properly initialized.
  31.  
  32.  
  33. -- 
  34. John Hickin      Nortel Technology, Montreal, Quebec
  35. (514) 765-7924   hickin@nortel.ca
  36.  
  37.